<template>
  <div class="visotor">
    <div class="top">
      <div class="left">
        <span class="free">{{ patient.isInsure == 1 ? '医保' : '自费' }}</span>
        <span class="username">{{ patient?.name }}</span>
      </div>
      <div class="right">
        <el-button
          type="primary"
          circle
          :icon="Edit"
          @click.prevent="handleEditPatient"></el-button>
        <el-button type="danger" circle :icon="Delete" @click.prevent="deletePatient"></el-button>
      </div>
    </div>
    <ul class="bottom">
      <li>
        <span class="label">证件类型：</span>
        <span class="value">{{ patient?.param?.certificatesTypeString }}</span>
      </li>
      <li>
        <span class="label">证件号码：</span>
        <span class="value">{{ patient?.certificatesNo }}</span>
      </li>
      <li>
        <span class="label">用户性别：</span>
        <span class="value">{{ patient?.sex == 1 ? '男' : '女' }}</span>
      </li>
      <li>
        <span class="label">出生日期：</span>
        <span class="value">{{ patient?.birthdate }}</span>
      </li>
      <li>
        <span class="label">手机号码：</span>
        <span class="value">{{ patient?.phone }}</span>
      </li>
      <li>
        <span class="label">婚姻状况：</span>
        <span class="value">{{ patient?.isMarry ? '已婚' : '未婚' }}</span>
      </li>
      <li>
        <span class="label">当前住址：</span>
        <span class="value">{{ patient?.param?.provinceString + patient.param.cityString }}</span>
      </li>
      <li>
        <span class="label">详细地址：</span>
        <span class="value">{{ patient?.param?.fullAddress }}</span>
      </li>
    </ul>
    <transition name="isSelected">
      <div class="fade isSelected" v-if="isSelected">已选择</div>
    </transition>
  </div>
</template>

<script lang="ts" setup>
import { Edit, Delete } from '@element-plus/icons-vue'
import { ElNotification, ElMessageBox } from 'element-plus'
import { reqDeletePatient } from '@/api/patient'
import { useRouter, useRoute } from 'vue-router'

let router = useRouter()
let route = useRoute()
// import { Patient } from '@/api/patient/type'
let $emits = defineEmits(['getList', 'editPatient'])
const $props = defineProps(['patient', 'isSelected'])
const deletePatient = async () => {
  await ElMessageBox.confirm('删除就诊人', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
  await reqDeletePatient($props.patient.id)
  ElNotification({
    title: '操作成功',
    message: '已删除',
    type: 'success'
  })
  $emits('getList')
}
const handleEditPatient = () => {
  // 获取当前路由
  let path = route.fullPath
  if (path.indexOf('hospital/register_step2') != -1) {
    router.push('/user/patient?type=update&id=' + $props.patient.id)
  } else {
    $emits('editPatient')
  }
}
</script>

<style lang="scss" scoped>
.visotor {
  box-shadow: 0 0 12px #efefef;
  border-radius: 4px;
  position: relative;
  .top {
    height: 50px;
    background-color: #efefef;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    justify-content: space-between;
    padding: 0px 20px;
    .left {
      .free {
        padding: 5px;
        background-color: #fff;
        font-size: 12px;
        margin-right: 8px;
        border-radius: 4px;
      }
      .username {
        color: #7f7f7f;
      }
    }
  }
  .bottom {
    padding: 10px 20px;
    overflow-y: scroll;
    li {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      font-size: 14px;
      line-height: 22px;
      height: 22px;
      .label {
        color: #444;
        width: 80px;
        min-width: 80px;
      }
      .value {
        color: #7f7f7f;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  .isSelected-enter-from {
    transform: scale(0.5);
  }
  .isSelected-enter-to {
    transform: scale(1.2);
  }
  .isSelected-enter-active {
    transition: all 1s;
  }
  .isSelected {
    position: absolute;
    top: 100px;
    width: 150px;
    height: 150px;
    left: 50%;
    display: flex;
    font-size: 20px;
    color: rgb(245, 104, 104);
    // font-weight: bold;
    transform: translateX(-50%) rotate(45deg);
    align-items: center;
    justify-content: center;
    border: 1px dashed red;
    border-radius: 50%;
    background-color: rgba($color: rgb(254, 221, 221), $alpha: 0.3);
  }
}
</style>
